using System;
using System.Collections.Generic;
using System.Text;
using SwinMessengerLibrary;

namespace SwinMessengerConsoleApp
{
    class MessageCommand: SwinMessengerCommand
    {
        /// <summary>
        /// This is the message command it will allow uses to send message to other people in there roster
        /// </summary>
        public MessageCommand()
            : base(new string[] { "msg", "message" })
        {
        }
        /// <summary>
        /// This executes the message command
        /// </summary>
        /// <param name="runOn">the server to send the message from</param>
        /// <param name="parameters">the id and messege to send</param>
        /// <returns>what the message command will print to the screen</returns>
        public override List<string> Execute(Server runOn, string[] parameters)
        {
            List<string> tempList = new List<string>();
            try
            {
                
                if (Convert.ToInt32(parameters[1]) > runOn.Roster.Contacts.Count - 1)
                {
                    tempList.Add("You do not have a contact with that number");
                }
                else
                {
                    Contact contact = runOn.Roster.Contacts[Convert.ToInt32(parameters[1])];
                    string message = "";
                    for (int i = 2; i < parameters.Length; i++)
                    {
                        message = message + " " + parameters[i];
                    }
                    runOn.SentTo(contact.Id, message);
                }
            }
            catch
            {
                tempList = MessageError();
            }
            return tempList;
        }

        private List<string> MessageError()
        {
            List<string> tempList = new List<string>();
            tempList.Add("You can not send a message like that!");
            tempList.Add("Type Help for a list of commands");
            return tempList;
        }

    }
}
